package cn.com.dhc.danlu.widget.terminal;

import android.content.Context;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.com.dhc.danlu.R;
import cn.com.hd.mall.web.webservices.entity.response.regist.TerminalRegistProgressResponse.RegistProgressBean;

public class TimeView extends LinearLayout {
    private View lineTop;
    private View lineBottom;
    private TextView tvTime;
    private TextView tvStatus;

    public TimeView (Context context) {
        super (context);

        initViews ();
    }

    public TimeView (Context context, AttributeSet attrs) {
        super (context, attrs);

        initViews ();
    }

    public void setData (RegistProgressBean data) {
        setTime (data.getTime ());
        setStatus (data.getDescription (), data.getReason ());
    }

    private void initViews () {
        View parent = LayoutInflater.from (getContext ()).inflate (R.layout.item_time_line, this, true);
        this.lineTop = parent.findViewById (R.id.line_top);
        this.lineBottom = parent.findViewById (R.id.line_bottom);
        this.tvTime = (TextView) parent.findViewById (R.id.tv_time);
        this.tvStatus = (TextView) parent.findViewById (R.id.tv_status);
    }

    public void setLineTopVisible (int visible) {
        lineTop.setVisibility (visible);
    }

    public void setLineBottomVisible (int visible) {
        lineBottom.setVisibility (visible);
    }

    public void setTime (String time) {
        tvTime.setText (time);
    }

    public void setStatus (String status, String reason) {
        if (TextUtils.isEmpty (reason)) {
            tvStatus.setText (status);
        } else {
            String tem = status + "(原因:" + reason + ")";
            SpannableString color = new SpannableString (tem);
            color.setSpan (new ForegroundColorSpan (getResources ().getColor (R.color.color_f78053)), status.length () + 1, tem.length () - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            tvStatus.setText (color);
        }
    }
}